home *** CD-ROM | disk | FTP | other *** search
- /*
- * file: Instrument Editor Filing.c
- *
- * started 12 January 1992 09:34
- * david van brink
- *
- * The filing routines
- *
- */
-
-
- /*--------------------------
- Inclusions
- --------------------------*/
-
- #include <ImageCompression.h>
- #include <Resources.h>
- #include <Errors.h>
- #include <Memory.h>
-
- #include "BigEasy2.h"
- #include "BigEasyDialogs.h"
- #include "BigEasyGrafish.h"
-
- #include "Instrument Editor.h"
- #include "Instrument Editor Filing.h"
-
- /*--------------------------
- Local Prototypes
- --------------------------*/
-
- static OSErr InternalSaveData(TDoc *d);
- static void DoIEPreview(TDoc *d,short resRefNum);
-
- /*--------------------------
- Wasabe
- --------------------------*/
-
- void OpenDoc(short n,short item, short ref)
- {
- StandardFileReply sfr;
- OSType ourType[5];
- ourType[0] = kDocumentFileType;
- StandardGetFilePreview(nil,1,ourType,&sfr);
-
- if(sfr.sfGood)
- {
- OpenDocSpec(&sfr.sfFile);
- }
- }
-
-
- void OpenDocSpec(FSSpec *fSpec)
- {
- short i;
- short refNum;
- register TDoc *d;
- TSaveRecord **sr;
- FInfo fileInfo;
-
- for(i = 0; i<kDocMax; i++)
- {
- d = &gDoc[i];
- if(!d->used)
- goto gotOne;
- }
-
- EasyDialogMessage(0,(StringPtr)0x910,"\pNo more windows may be opened.",
- kEasyDialogOkay);
- goto goHome;
-
- gotOne:
- refNum = FSpOpenResFile(fSpec,fsRdPerm);
- if(refNum == 1)
- goto fileError;
- sr = (void *)Get1IndResource(kDocumentResType,1);
- if(!sr)
- goto closeAndFileError;
- HLock((void *)sr);
- if((**sr).docVersion != kDocVersion)
- {
- EasyDialogMessage(0,fSpec->name,
- "\pThat was an old version of the file format.",
- kEasyDialogOkay);
- goto closeAndFileError;
- }
-
- d->used = true;
- d->docSpec = *fSpec;
- NewDocFromSaveRecord(i,&(**sr),0);
- CloseResFile(refNum);
-
- goto goHome;
-
- closeAndFileError:
- CloseResFile(refNum);
- fileError:
- EasyDialogMessage(0,fSpec->name,
- "\pThere was a problem opening the file.",
- kEasyDialogOkay);
-
- goHome:;
- }
-
-
-
-
-
- short SaveDoc(short n,short item, short ref)
- /*
- * return nonzero to
- * say it was cancelled.
- */
- {
- TDoc *d;
-
- d = &gDoc[n - kFirstDocWindow];
-
- if(!d->everSaved)
- return SaveAsDoc(n,item,ref);
- else
- return InternalSaveData(d);
- }
-
- short SaveAsDoc(short n,short item, short ref)
- {
- StandardFileReply sfr;
- register TDoc *d;
- Boolean result;
- TSaveRecord *sr,**srH;
- short refNum;
- OSErr thisError;
- OSType fileType;
-
- d = &gDoc[n - kFirstDocWindow];
-
- StandardPutFile("\p",d->docSpec.name,&sfr);
-
- result = !sfr.sfGood;
- if(sfr.sfGood)
- {
- d->docSpec = sfr.sfFile;
- SetWTitle(d->w,d->docSpec.name);
- thisError = InternalSaveData(d);
- }
- else
- thisError = 1;
-
- return thisError;
- }
-
-
- OSErr InternalSaveData(TDoc *d)
- {
- TSaveRecord **srH,*sr;
- short refNum;
- OSErr thisError;
- Rect r;
- long i;
-
-
- srH = (void *)NewHandle(sizeof(TSaveRecord));
- HLock((void *)srH);
- sr = *srH;
-
- sr->docVersion = kDocVersion;
- SetPort(d->w);
- sr->windowRect = qd.thePort->portRect;
- LocalToGlobal((Point *)&sr->windowRect.top);
- LocalToGlobal((Point *)&sr->windowRect.bottom);
- sr->sr = d->sr;
-
- HUnlock((void *)srH);
-
- FSpCreateResFile(&d->docSpec,kCreatorFileType,kDocumentFileType,0);
-
- thisError = ResError();
- if(thisError == dupFNErr)
- thisError = 0;
- if(thisError)
- goto goHome;
-
- refNum = FSpOpenResFile(&d->docSpec,fsRdWrPerm);
-
- if(refNum != -1)
- {
- Replace1Resource((void *)srH,kDocumentResType,10);
-
- for(i = 0; i < d->instrumentCount; i++)
- Replace1Resource((Handle)d->instrument[i],kInstrumentListResType,i+1);
-
- d->changed = false;
- d->littleChanged = false;
- d->everSaved = true;
- DoIEPreview(d,refNum);
- CloseResFile(refNum);
-
- FixUpMenus(d);
- }
- else
- thisError = -1;
-
- goHome:
- return thisError;
- }
-
-
- #define kPreviewWidth 80
- #define kPreviewHeight 80
-
- void DoIEPreview(TDoc *d,short resRefNum)
- {
- Rect r;
- Point p;
- PicHandle pH;
- short i;
-
- r.left = r.top = 0;
- r.right = kPreviewWidth;
- r.bottom = kPreviewHeight;
-
- pH = OpenPicture(&r);
- p.v = kTextAllowance;
- p.h = 5;
-
- GoBW();
- TextFont(3);
- TextSize(9);
- TextFace(0);
-
- MoveTo(p.h,p.v);
- DrawChar('“');
- DrawString(d->sr.synthName);
- DrawChar('”');
-
- i = 0;
- while(i < d->instrumentCount && p.v < kPreviewHeight-5)
- {
- p.v += kTextAllowance;
- MoveTo(p.h,p.v);
- DrawString((**d->instrument[i]).tone.instrumentName);
- i++;
- }
-
- ClosePicture();
- AddFilePreview(resRefNum,'PICT',(Handle)pH);
-
- KillPicture(pH);
- }
-
-